package cn.com.twoke.game.client.games.tic_tac_toe.entity;

import cn.com.twoke.game.client.games.tic_tac_toe.constants.TicTacToeChess;
import cn.com.twoke.game.client.games.tic_tac_toe.constants.TicTacToeGameConstant;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class TicTacToeChessImpl implements TicTacToeChess {

    private boolean display;
    private TicTacToeChess.Type type;
    private Point position;
    private Rectangle2D hitbox;

    public TicTacToeChessImpl(int x, int y) {
        this.display = false;
        this.type = Type.NONE;
        this.position = new Point(x, y);
        this.hitbox = new Rectangle2D.Double(
                TicTacToeGameConstant.cellX(x),
                TicTacToeGameConstant.cellY(y) , TicTacToeChess.CELL_WIDTH, TicTacToeChess.CELL_WIDTH);
    }

    @Override
    public void update(double deltaU) {

    }

    public boolean isDisplay() {
        return display;
    }

    @Override
    public void render(Graphics2D g) {
        if (this.type != Type.NONE && this.display) {
            this.type.render(g, this.position.x, this.position.y);
        }
    }

    @Override
    public void show() {
        this.display = true;
    }
    public boolean isDrop() {
        return this.type != TicTacToeChess.Type.NONE;
    }
    @Override
    public void hide() {
        this.display = false;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public void drop(Type type) {
        this.setType(type);
        this.show();
    }

    public Point getPosition() {
        return position;
    }

    public Rectangle2D getHitbox() {
        return hitbox;
    }

    public void setPosition(int x, int y) {
        this.position.y = y;
        this.position.x = x;
        this.hitbox.setRect(TicTacToeGameConstant.cellX(x),
                TicTacToeGameConstant.cellY(y) , TicTacToeChess.CELL_WIDTH, TicTacToeChess.CELL_WIDTH);
    }
}
